package com.pf.common.utils;

import com.pf.common.dto.BaseResult;
import com.pf.common.enums.BaseResultEnum;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2022/7/1 21:58
 */
public class BaseResultUtils {

    /**
     * 调用成功
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> BaseResult success(T data) {
        BaseResult result = new BaseResult();
        result.setSuccess(true);
        result.setCode(BaseResultEnum.SUCCESS.getCode());
        result.setMessage(BaseResultEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    /**
     * 调用成功
     *
     * @return
     */
    public static BaseResult success() {
        return success(null);
    }

    /**
     * 调用失败
     *
     * @param code
     * @param message
     * @return
     */
    public static BaseResult fail(Integer code, String message) {
        BaseResult result = new BaseResult();
        result.setSuccess(true);
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    /**
     * 调用失败
     *
     * @param message
     * @return
     */
    public static BaseResult fail(String message) {
        return fail(BaseResultEnum.FAIL.getCode(), message);
    }

    /**
     * 调用失败
     *
     * @param resultRespEnum
     * @return
     */
    public static BaseResult fail(BaseResultEnum resultRespEnum) {
        return fail(resultRespEnum.getCode(), resultRespEnum.getMessage());
    }

}
